package com.jk.admin.controller;

import com.jk.admin.entity.BannerEntity;
import com.jk.admin.service.BannerService;
import com.jk.admin.utils.OSSUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
public class BannerController {

    @Autowired
    private BannerService bannerService;

    @RequestMapping("getBanner")
    public List<BannerEntity>  getBanner(){
        List<BannerEntity> banner = bannerService.getBanner();
        return banner;
    }
    @RequestMapping("geIdBan")
    public BannerEntity getById(Integer id){
        return bannerService.getById(id);
    }

    @RequestMapping("updBan")
    public void updBan(BannerEntity bannerEntity, HttpServletRequest request){
        String img = (String) request.getSession().getAttribute("img");
        bannerEntity.setImg(img);
        System.out.println(img+"-----s----ss------s-----");
        bannerService.updBan(bannerEntity);
    }
    @RequestMapping("upload1")
    public Map upload(MultipartFile img, HttpServletRequest request) throws Exception{
        String upload2oss = OSSUtil.upload2oss(img);
        System.out.println(upload2oss);
        request.getSession().setAttribute("img", upload2oss);
        Map map=new HashMap<>();
        map.put("upload2oss", upload2oss);
        return map;
    }
}
